package io.github.i678.bukkitantipmc;

import io.github.i678.bukkitantipmc.listeners.ChatFilter;
import io.github.i678.bukkitantipmc.utils.ChatUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

/**
 * Main file for the AntiFakePMC plugin.
 * @author TheNameMan
 * @since The beginning of time
 * @version 2.0.0
 */
public class AntiFakePMC extends JavaPlugin {

public static String notify = "permissions";
public static String version = "2.0.0-ALPHA-1";
public static boolean severe = true;
public static boolean logEnabled = true;
public static boolean debug = false;
public static boolean dev = true;
public static String messageNormal = ChatColor.GREEN + "AntiFakePMC » " + ChatColor.GRAY;
public static String messageDebug = ChatColor.GREEN + "AntiFakePMC [DEBUG] » " + ChatColor.GRAY;
public static String messageWarn = ChatColor.YELLOW + "AntiFakePMC [WARNING] » " + ChatColor.GOLD;
public static String messageSevere = ChatColor.DARK_RED + "AntiFakePMC [SEVERE] » " + ChatColor.RED;
public static String messageFatal = ChatColor.DARK_RED + "AntiFakePMC [FATAL] » " + ChatColor.RED;

public static String console = "AntiFakePMC > ";

private final List<String> aliases = new ArrayList<>();

@Override
    public void onEnable() {
        if(getConfig().getBoolean("plugin.forceDev")) {
            dev = true;
        }
	if(getConfig().getBoolean("plugin.debug")) {
        debug = true;
	}
	if(dev) {
            ChatUtils.logMessage(Level.INFO, "Plugin starting up with DEV mode active.");
            ChatUtils.logMessage(Level.INFO, "Current task: PLUGIN CHECKS");
            ChatUtils.logMessage(Level.INFO, "PLUGIN CHECKS done!");
            ChatUtils.logMessage(Level.INFO, "Current task: FILTER SETUP");
            getServer().getPluginManager().registerEvents(new ChatFilter(), this);
            ChatUtils.logMessage(Level.INFO, "FILTER SETUP done!");
            ChatUtils.logMessage(Level.INFO, "Current task: COMMAND SETUP");
            Bukkit.getPluginCommand("antifakepmc").setExecutor(new Command());
            setupAliases();
            Bukkit.getPluginCommand("antifakepmc").setAliases(aliases);
            ChatUtils.logMessage(Level.INFO, "COMMAND SETUP done!");
            ChatUtils.logMessage(Level.INFO, "AntiFakePMC v" + version + " is now enabled!");
	} else {
            ChatUtils.logMessage(Level.INFO, console + "Plugin starting up...");
            getServer().getPluginManager().registerEvents(new ChatFilter(), this);
            getConfig().options().copyDefaults(true);
            saveConfig();
            Bukkit.getPluginCommand("antifakepmc").setExecutor(new Command());
            setupAliases();
            Bukkit.getPluginCommand("antifakepmc").setAliases(aliases);
            ChatUtils.logMessage(Level.INFO, "AntiFakePMC v" + version + " is now enabled!");
        }
    }

    private void setupAliases() {
        aliases.add("apmc");
        aliases.add("nopmc");
        aliases.add("pmc");
        aliases.add("antipmc");
    }

    @Override
    public void onDisable() {
        ChatUtils.logMessage(Level.INFO, "AntiFakePMC is now disabled!");
	}

}